//
//  WBHomeViewController.swift
//  新浪微博
//
//  Created by 陈飞宇 on 2020/9/24.
//

import UIKit

private let cellId = "cellId"
class WBHomeViewController: WBBaseViewController {

    private lazy var statusList = [String]();
    
    override func viewDidLoad() {
        super.viewDidLoad()

//        tableView?.mj_header?.beginRefreshing();

    }
    
    override func loadData() {
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
            for i  in 0..<15 {
                //将数据插入顶部
                self.statusList.insert(i.description, at: 0);
            }
            self.tableView?.mj_header?.endRefreshing();
            self.tableView?.reloadData();
         }
      
    }
    
    
    //显示好友
    @objc private func showFriends()  {
        print(#function);
        
    }
}

// MARK: --表格数据源方法
extension WBHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count;
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)  ;

        cell.textLabel?.text = statusList[indexPath.item]
        
        return cell;
    }

}

extension WBHomeViewController{
    
    //重写父类方法
    override func setUpUI() {
        super.setUpUI();
        
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends));
        
        self.tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId);
    }
}
